package com.dmz.wxcp.wecom.wxbusiness.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dmz.wxcp.wecom.wxbusiness.entity.Article;
import com.dmz.wxcp.wecom.wxbusiness.entity.ReadRecord;
import com.dmz.wxcp.wecom.wxbusiness.entity.TagRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

    IPage<Article> getArticleList(IPage<Article> iPage);

    @Select("select a.id,a.title,a.page_view,a.update_time,a.content,a.images,a.tags,user.login_name"+
            " from article a join user on a.user_id=user.id" +
            " where a.id=#{id}")
    Article getArticleDetail(Long id);

    @Select("select a.id,a.title,a.page_view,a.update_time,a.content,a.images,a.tags,user.login_name"+
            " from article a join user on a.user_id=user.id" +
            " where a.id=#{id}")
    Article getStudyArticleDetail(Long id);

    @Select("select id,title,images,page_view from article where category_id=6 and is_display=1")
    List<Article> getProductDisplayArticles();

    @Select("select article.id as id,title,images,page_view,login_name,content from article join user on article.user_id=user.id where category_id=7 and is_display=1")
    List<Article> getStudyDisplayArticles();

    @Update("update article set page_view=page_view+1 where id=#{id}")
    Integer upDateArticlePageView(Long id);

    @Insert("insert into read_records (contactid,articleid) values (#{readRecord.contactid},#{readRecord.articleid})")
    Integer insertReadRecords(@Param("readRecord")ReadRecord readRecord);

    @Insert("insert into tag_records (contactid,tagid,type) values (#{tagRecord.contactid},#{tagRecord.tagid},#{tagRecord.type})")
    Integer insertTagRecords(@Param("tagRecord") TagRecord tagRecord);
}
